package com.canplay.screen.network

import com.canplay.screen.utils.Md5Utils
import okhttp3.Interceptor
import okhttp3.Response
import java.util.UUID


class HeaderInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        builder.apply {
            val timestamp = System.currentTimeMillis().toString()
            val nonceStr = UUID.randomUUID().toString()
            val sign = Md5Utils.generateSaltedMD5Signature(timestamp, nonceStr).toString();
            addHeader("timestamp", timestamp)
            addHeader("nonceStr", nonceStr)
            addHeader("sign",sign)
            addHeader("Content-Type","application/json")
        }
        return chain.proceed(builder.build())
    }
}